package com.meta.platform.login.plus.common.enums;

import java.util.Arrays;
import java.util.Optional;

/**
 * 发送验证码渠道
 *
 * @author pengjianfeng
 * @version 1.0
 * @date 2021/1/11 3:07 下午
 */
public enum VCodeChannel {
    
    SMS(1, "短信"), MAIL(2, "邮件");
    
    private int code;
    
    private String name;
    
    VCodeChannel(int code, String name) {
        this.code = code;
        this.name = name;
    }
    
    public int getCode() {
        return code;
    }
    
    public String getName() {
        return name;
    }
    
    public static VCodeChannel getChannel(int code) {
        return Arrays.stream(VCodeChannel.values()).filter(channel -> channel.getCode() == code).findFirst().orElse(null);
    }
    
    public static VCodeChannel getChannelDefault(int code, VCodeChannel vCodeChannel) {
        return Optional.ofNullable(getChannel(code)).orElse(vCodeChannel);
    }
}
